/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.            */
/*                                                                 */
/*  NAME      = t_sqlserver_init_response.c                        */
/*  NOTE      =                                                    */
/*  DATE      = 2015/02/26 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <frcomm.h>
#include <sqlserver/config.h>
#include <sqlserver/sqlserver_core.h>
#include <sqlserver/sqlserver_common.h>

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    L7_resp_sqlserver *p_st_resp = NULL;
    int i_tds_ver = 2;
    int i_tds_min_ver = 0;
    int i_tds_max_ver = 4;

    sqlserver_init_response(p_st_resp, i_tds_ver, i_tds_min_ver, i_tds_max_ver);

    CU_ASSERT_PTR_NULL(p_st_resp);

    return;
}

static void __case2(void)
{
    L7_resp_sqlserver *p_st_resp = NULL;
    int i_tds_ver = 2;
    int i_tds_min_ver = 0;
    int i_tds_max_ver = 4;

    p_st_resp = (L7_resp_sqlserver *) frmalloc(sizeof(L7_resp_sqlserver));
    memset(p_st_resp, 0x00, sizeof(L7_resp_sqlserver));

    sqlserver_init_response(p_st_resp, i_tds_ver, i_tds_min_ver, i_tds_max_ver);

    CU_ASSERT_EQUAL(p_st_resp->i_ser_tds_ver_tmp, 2);
    CU_ASSERT_EQUAL(p_st_resp->i_ser_tds_min_ver_tmp, 0);
    CU_ASSERT_EQUAL(p_st_resp->i_ser_tds_max_ver_tmp, 4);

    sqlserver_destroy_response(&p_st_resp);

    return;
}

int add_suite_sqlserver_init_response(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" sqlserver_init_response()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
